package com.example.yls.demoa;

import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    private Button btnCreateDB;
    private Button btnCreateTable;
    private Button btnInsert;
    private SQLiteDatabase db;
    private String Editno;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnCreateDB=findViewById(R.id.CreateDB);
        btnCreateTable=findViewById(R.id.CreateTable);
        btnInsert=findViewById(R.id.InsertDB);

        btnCreateTable.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                createTable();
            }
        });
        btnInsert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                InsertDate();
            }
        });
    }

    private void InsertDate() {
    }

    private void createTable() {
        if(db == null){
            CreateOrOpenDB();
        }
        String sql ="create table if not exists student (stuno varchar(20), name varchar(20), age int)";
        db.execSQL(sql);

    }
    private void CreateOrOpenDB(){
        String path = getFilesDir().getAbsolutePath() + File.separator + "stu.db";
        Log.e("MainActivity","path=" + path);

        db = SQLiteDatabase.openOrCreateDatabase(path , null);
    }
}
